﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Text;
using Mail.MiniProgram.Core.Security;

namespace Mail.MiniProgram.Core.Dto
{
    public class WxOpenLoginDto
    {
        [Required]
        public string Code { get; set; }

        public string ErrMsg { get; set; }

        public string Signature { get; set; }

        public string EncryptedData { get; set; }

        public string Iv { get; set; }

        public string RawData { get; set; }

        public UserInfoDto UserInfo { get; set; }

        public bool ValidateSign(string key)
        {

           
            var encryptedSign = (this.RawData + key).SHA1();
            return string.Equals(this.Signature, encryptedSign, StringComparison.OrdinalIgnoreCase);
         
        }

        public string DecryptionData(string key)
        {
            return this.EncryptedData.Decrypt(key,this.Iv);
        }
    }
}
